package com.example.view.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

public class LimitlessViewPagerAdapter extends PagerAdapter {

    private int[] imgIds;

    public LimitlessViewPagerAdapter(int[] imgIds) {
        this.imgIds = imgIds;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        position = position % imgIds.length;
        ImageView img = new ImageView(container.getContext());
        img.setImageResource(imgIds[position]);
        img.setScaleType(ImageView.ScaleType.FIT_XY);
        container.addView(img);
        return img;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }
}
